package com.imooc.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.time.LocalDateTime;

@Getter
@Setter
public class BaseEntity<T extends Model<T>> extends Model<T> {

    /**
     * 系统id
     */
    @TableId(type = IdType.ASSIGN_ID)
    public Long id;

    /**
     * 创建人id
     */
    @TableField(fill = FieldFill.INSERT)
    private Long createBy;

    /**
     * 创建人部门id
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Long createDeptId;

    /**
     * 创建时间
     */
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
    private LocalDateTime createTime;

    /**
     * 更新人id
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Long updateBy;

    /**
     * 更新时间
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
    private LocalDateTime updateTime;

    /**
     * 删除标记
     */
    @TableLogic(value = "0", delval = "1")
    @TableField(fill = FieldFill.INSERT)
    public Integer flagDel;

    /**
     * 商户编码
     */
    @TableField(fill = FieldFill.INSERT)
    private String companyCode;

    /**
     * 数据版本号
     */
    @Version
    @TableField(fill = FieldFill.INSERT)
    private Integer version;

    @Override
    public Serializable pkVal() {
        return this.id;
    }
}
